﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{
    /*
     * A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012   021   102   120   201   210

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

     * 
     * 
     

     
     * 0123
     * 0132
     * 0213
     * 0231
     * 0312
     * 0321
     * 1023
     * 1032
     * 1203
     * 1230
     * 1302
     * 1320
     * 2013
     * 2031
     * 2103
     * 2130
     * 2301
     * 2310
     * 3012
     * 3021
     * 3102
     * 3120
     * 3201
     * 3210
     * */
    class Problem24
    {
        public static string Calculate()
        {
            long result = 1;

            for (long i = 1; i <= 8; i++)
                result *= i;

            //int limit = 3;

            //prva *znamenka (redna od onih preostalih!)
            long res = 2 * Factoriel(9) + 6 * Factoriel(8) + 6 * Factoriel(7) + 2 * Factoriel(6) + 5 * Factoriel(5)
               + 1 * Factoriel(4) + 2 * 6 + 1 * 2 + 1 * 1 + 1;

            //long res = 1 * 6 + 2 * 2 + 0 * 1;

            //raspolozive su           
            //znamenke su 2 6 6 2 5 1 2 1 1 0 po redu ostajanja;
            //rjesenje  2783915460 


            return res.ToString();
        }

        static long Factoriel(int n)
        {
            long res = 1;
            for (int i = 1; i <= n; i++)
                res *= i;
            return res;
        }
    }
}
